@extends('steward.layoutList')
@section('css')
    <style type="text/css">
        .app-title {

        }

        .fixed-table-container {
            height : 400px !important;
        }
    </style>
@endsection
@section('title')
    <span style="line-height: 48px;">商品规格管理</span>
@endsection
@section('title_btn')
    <button type="button" class="btn btn-info layer-go-back">返回</button>
@endsection
@section('search')
    <input type="text" class="form-control" placeholder="请输入商品编码" name="product_code"/>
@endsection
@section('js')
    <script>

        var mainPostID = '{{ $mainPostID }}';
        var bootstrap_table_ajax_url = '/lar/steward/goods/search_spec/' + mainPostID;
        bootstrap_table({
            sortName : 'goods_sale.timeStamp',
            sortOrder : 'desc',
            columns: [ //字段
                { title: '操作', field: 'operation', align: 'center' , width:'100px' },
                { title: '商品状态', field: 'forsale', align: 'center' , width:'100px' },
                { title: '商品名称',  field: 'goodsName', align: 'left' },
                { title: '规格',  field: 'spec', align: 'left' },
                { title: '商品编码/条形码', field: 'product_code', align: 'left', width:'150px' },
                { title: '价格', field: 'salePrice', align: 'left', width:'100px' },
                { title: '可售库存', field: 'enableSaleAmount', align: 'left', width:'100px' }
            ]
        });

        $(document).on('click','.forsale',function() {       //商品上禁用操作
            var type = $(this).attr('data_type');           //操作方式
            var mainPostID = $(this).attr('data_mainPostID') ;//主商品
            var err_msg = '';                               //错误信息
            var title = '';                                 //提示
            var id_arr = [];                               //操作对象

            if (type == 1) {
                title = '禁用';
            } else {
                title = '启用';
            }

            //单独操作
            var id = $(this).attr('data_id');
            if (E.isInt(id) && id > 0) {
                title = '您确定将该商品' + title + '吗？';
                id_arr.push(id);
            } else {
                err_msg = '参数错误，请刷新页面';
            }

            if (err_msg) {
                layer.msg(err_msg, {icon: 2, shade: [0.15, 'black'], offset: '120px', time: 1000});
                return false;
            }

            layer.confirm(title, {icon: 3, offset: '50px'}, function (index) {

                layer.close(index);

                E.ajax({
                    type: 'get',
                    url: '/lar/steward/good/change_sale',
                    data: {
                        'type': type,
                        'flag': 1,     //0 主商品  1 规格商品
                        'mainPostID' : mainPostID,
                        'data': id_arr
                    },
                    success: function (o) {
                        if (o.code == 200) {
                            layer.msg(o.message, {icon: 1, time: 1000});
                            bootstrap_table_init();
                        } else {
                            layer.msg('操作失败', {icon: 2, time: 1000});
                        }
                    }
                });
            })
        }).on('click','.layer-go-back',function(){
            parent.bootstrap_table_init();
        })
    </script>
@endsection